// pages/applied/applied.js
const app = getApp()
import api from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetailInfo:{},
    showLogin: false,
    card: {},
    imgUrl: ''
  },
  openMap() {
    console.log('map')
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userLocation']) {
          wx.authorize({
            scope: 'scope.userLocation',
            success() {
              wx.getLocation({
                type: 'wgs84',
                success: function (res) {
                  let latitude = res.latitude
                  let longitude = res.longitude
                  wx.openLocation({
                    latitude,
                    longitude,
                    scale: 28
                  })
                }
              })
            }
          })
        }
      }
    })

  },

  // 复制考点
  copyVenues() {
    console.log(this.data.orderDetailInfo)
    let info = this.data.orderDetailInfo
    let venues = info.province_name + (info.city_name ? info.city_name : '') + (info.area_name ? info.area_name : '') + (info.address ? info.address : '')

    wx.setClipboardData({
      data: venues,
      success() {
        wx.getClipboardData({
          success(res) {
            console.log(res.data)
          }
        })
      }
    })
  },

  showModal() {
    let obj = {}
    obj.order_identifier = this.data.orderDetailInfo.order_identifier
    console.log(obj.order_identifier)
    api.POST('/applet/exam_order/checkExamPermit', obj, res => {
      // 准考证
      console.log(res.data)
      this.setData({
        card: res.data
      })
    })

    api.POST('/applet/ContactService/detail', {}, res => {
      console.log(res.data.exam_card_url)
      this.setData({
        imgUrl: res.data.exam_card_url
      })
    })
    this.setData({
      showLogin: true
    })
  },
  close() {
    this.setData({
      showLogin: false
    })
    console.log(123)
  },

  savePermit() {
    let that = this
    wx.setClipboardData({
      data: this.data.card.card_identifier,
      success() {
        wx.getClipboardData({
          success(res) {
            wx.showToast({
              title: '保存准考证成功',
            })
            that.close()
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.oid)
    api.POST('/applet/exam_order/detail', {
      exam_order_id: options.oid
    }, res => {
      console.log(res)
      console.log(res.data.exam_status, res.data.status)
      this.setData({
        orderDetailInfo: res.data
      })
      console.log(res.data)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})